package main

import (
	"context"
	"fmt"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
	"learn_grpc/2_grpc/grpc_test/proto"
)

func main() {
	// 建立连接 grpc.WithTransportCredentials(insecure.NewCredentials())跳过证书验证
	conn, err := grpc.Dial("127.0.0.1:8080", grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		panic(err)
	}
	defer conn.Close() //需要关闭连接，
	// 初始化客户端
	client1 := proto.NewGreeterClient(conn)
	resq := proto.HelloRequest{
		Name: "John",
	}
	//发出请求
	respon, err := client1.SayHello(context.Background(), &resq)
	if err != nil {
		panic(err)
	}
	fmt.Println(respon.Message)
}
